# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=qscintilla
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.11.5
pkgrel=1
pkgdesc="A port to Qt5 of Neil Hodgson's Scintilla C++ editor class (mingw-w64)"
arch=('any')
license=("GPL")
url="https://riverbankcomputing.com/software/qscintilla/intro"
depends=("${MINGW_PACKAGE_PREFIX}-qt5")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-sip5"
             "${MINGW_PACKAGE_PREFIX}-pyqt-builder"
             "${MINGW_PACKAGE_PREFIX}-pyqt5-sip"
             "${MINGW_PACKAGE_PREFIX}-python-pyqt5")
options=(!strip staticlibs !buildflags)
source=(https://www.riverbankcomputing.com/static/Downloads/QScintilla/${pkgver}/QScintilla-${pkgver}.tar.gz
        'run-command-via-sh.patch'
        'qmake-install-paths.patch'
        'designed-plugin-config-build.patch'
        'proper-module-extension.patch')
sha256sums=('9361e26fd7fb7b5819a7eb92c5c1880a18de9bd3ed9dd2eb008e57388696716b'
            'a517b6427006c18db816dfcd087eee36e2f08c48c5147c48971f25118ea0c149'
            '517df6924d9d10104ee57372530692457cc3d4687d98ee6222f9764f0b31024b'
            'b9de93dc99426bebcb9516942b70b0cd8b17cba62de79becceb04737a1b0a2e7'
            'd574fa11c432a08653544c914d6da75d3cbc5ca8642ea16e90ed62af8c0cda4d')

prepare() {
  cd QScintilla-${pkgver}
  patch -p1 -i "${srcdir}"/run-command-via-sh.patch
  patch -p1 -i "${srcdir}"/qmake-install-paths.patch
  patch -p1 -i "${srcdir}"/designed-plugin-config-build.patch
  patch -p1 -i "${srcdir}"/proper-module-extension.patch
}

package_qscintilla() {
  pkgdesc="A port to Qt5 of Neil Hodgson's Scintilla C++ editor class"
  depends=("${MINGW_PACKAGE_PREFIX}-qt5")

  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin

  cd ${srcdir}/QScintilla-${pkgver}
  sed -e "s|%INSTALL_PREFIX%|$(cygpath -wm ${pkgdir})|g" \
    -i Qt4Qt5/qscintilla.pro \
    -i designer-Qt4Qt5/designer.pro

  cd Qt4Qt5
  ${MINGW_PREFIX}/bin/qmake CONFIG+=release CONFIG+=force_debug_info CONFIG+=separate_debug_info qscintilla.pro
  make install
  mv "${pkgdir}"/${MINGW_PREFIX}/lib/*.debug "${pkgdir}"/${MINGW_PREFIX}/bin/

  cd ../designer-Qt4Qt5
  QMAKEFEATURES=../Qt4Qt5/features \
  ${MINGW_PREFIX}/bin/qmake CONFIG+=release INCLUDEPATH+=../Qt4Qt5 designer.pro
  make install

  mv ${pkgdir}${MINGW_PREFIX}/lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin/
}

package_python-qscintilla() {
  pkgdesc="Python bindings for QScintilla2"
  depends=("${MINGW_PACKAGE_PREFIX}-${_realname}"
           "${MINGW_PACKAGE_PREFIX}-python-pyqt5")
  provides=("${MINGW_PACKAGE_PREFIX}-python-qscintilla-common"
            "${MINGW_PACKAGE_PREFIX}-python3-qscintilla")
  conflicts=("${MINGW_PACKAGE_PREFIX}-python-qscintilla-common"
             "${MINGW_PACKAGE_PREFIX}-python3-qscintilla")
  replaces=("${MINGW_PACKAGE_PREFIX}-python-qscintilla-common"
            "${MINGW_PACKAGE_PREFIX}-python3-qscintilla")

  cd QScintilla-${pkgver}
  ${MINGW_PREFIX}/bin/sip-build \
    --no-make \
    --qsci-features-dir=Qt4Qt5/features \
    --qsci-include-dir=Qt4Qt5 \
    --qsci-library-dir=Qt4Qt5 \
    --api-dir=${MINGW_PREFIX}/share/qt5/qsci/api/python \
    --verbose

  cd build
  make
  MSYS2_ARG_CONV_EXCL="${MINGW_PREFIX}" \
  make INSTALL_ROOT="${pkgdir}" install -j1
}

### Wrappers

package_mingw-w64-i686-qscintilla() {
  package_qscintilla
}

package_mingw-w64-i686-python-qscintilla() {
  package_python-qscintilla
}

package_mingw-w64-x86_64-qscintilla() {
  package_qscintilla
}

package_mingw-w64-x86_64-python-qscintilla() {
  package_python-qscintilla
}
